/*
 * @Author: 小花
 * @Date: 2022-05-21 19:32:28
 * @LastEditors: 小花
 * @LastEditTime: 2022-06-12 18:35:49
 * @FilePath: /permission_client/src/request/index.ts
 * @Description:
 */
import { ILoginForm } from '@/model/LoginView'
import { IMenuType } from '@/model/MenuTypeView'
import { IMenu } from '@/model/MenuView'
import { IPermission, IRole } from '@/model/RoleView'
import { IUser } from '@/model/UserView'
import { AxiosRequestConfig } from 'axios'
import axios from './axios'

// ==============================登录请求==============================

/**
 * @description: 登录
 * @param {ILoginForm} data
 * @return {*}
 */
export const doLogin = (data: ILoginForm) => {
  return axios.post('/login/doLogin', data)
}

/**
 * @description: 注册
 * @param {ILoginForm} data
 * @return {*}
 */
export const doRegister = (data: ILoginForm) => {
  return axios.post('/login/doRegister', data)
}

/**
 * @description: 登出
 * @param {*}
 * @return {*}
 */
export const logout = () => {
  return axios.get('/login/logout')
}

// ==============================用户请求==============================

/**
 * @description: 拉取用户信息
 * @param {*}
 * @return {*}
 */
export const pullAllUser = () => {
  return axios.get('/user/pullAllUser')
}

/**
 * @description: 更新/添加用户
 * @param {IUser} data
 * @return {*}
 */
export const updateUser = (data: IUser) => {
  return axios.post('/user/updateUser', data)
}

/**
 * @description: 删除用户
 * @param {string} idList 用户id列表
 * @return {*}
 */
export const delUser = (idList: string[]) => {
  return axios.post('/user/delUser', idList)
}

/**
 * @description: 上传用户头像
 * @param {FormData} formData
 * @return {*}
 */
export const uploadAvatar = (formData: FormData, config?: AxiosRequestConfig<FormData>) => {
  return axios.post('/user/uploadAvatar', formData, config)
}

// ==============================角色请求==============================

/**
 * @description: 拉取所有角色列表
 * @param {*}
 * @return {*}
 */
export const pullAllRole = () => {
  return axios.get('/role/pullAllRole')
}

/**
 * @description: 更新/添加角色
 * @param {IRole} role
 * @return {*}
 */
export const updateRole = (role: IRole) => {
  return axios.post('/role/updateRole', role)
}

/**
 * @description: 删除角色
 * @param {string} idList
 * @return {*}
 */
export const delRoles = (idList: string[]) => {
  return axios.post('/role/delRoles', idList)
}

// ==============================菜单请求==============================

/**
 * @description: 拉取菜单类型
 * @param {*}
 * @return {*}
 */
export const pullAllMenuType = () => {
  return axios.get('/menuType/pullAllMenuType')
}

/**
 * @description: 添加菜单类型
 * @param {IMenuType} data
 * @return {*}
 */
export const addMenuType = (data: IMenuType) => {
  return axios.post('/menuType/addMenuType', data)
}

/**
 * @description: 删除菜单类型
 * @param {string} idList
 * @return {*}
 */
export const delMenuType = (idList: string[]) => {
  return axios.post('/menuType/delMenuType', idList)
}

/**
 * @description: 编辑菜单类型
 * @param {IMenuType} data
 * @return {*}
 */
export const editMenuType = (data: IMenuType) => {
  return axios.post('/menuType/editMenuType', data)
}

/**
 * @description: 拉取所有菜单权限
 * @param {*}
 * @return {*}
 */
export const pullAllMenuPermission = () => {
  return axios.get('/menu/pullAllMenuPermission')
}

/**
 * @description: 更新菜单权限
 * @param {IMenu} data
 * @return {*}
 */
export const updateMenuPermission = (data: IMenu) => {
  return axios.post('/menu/updateMenuPermission', data)
}

/**
 * @description: 删除菜单权限
 * @param {string} idList
 * @return {*}
 */
export const delMenuPermission = (idList: string[]) => {
  return axios.post('/menu/delMenuPermission', idList)
}

// ==============================权限请求==============================

/**
 * @description: 获取所有权限信息
 * @param {*}
 * @return {*}
 */
export const pullAllRolePermission = () => {
  return axios.get('/role/pullAllRolePermission')
}

/**
 * @description: 更新/添加角色权限
 * @param {IPermission} data 角色权限
 * @return {*}
 */
export const updateRolePermission = (data: IPermission[]) => {
  return axios.post('/role/updateRolePermission', data)
}

/**
 * @description: 获取所有用户角色信息
 * @param {*}
 * @return {*}
 */
export const pullAllUserRole = () => {
  return axios.get('/user/pullAllUserRole')
}
